﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DM_SSSDBM
{
    public partial class ServerLogin : Form
    {
        public SqlConnection MainSQLCon = new SqlConnection();
        public bool ConStat = false;
        public ServerLogin()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (UseWin.Checked)
            {
                Username.Clear();
                Password.Clear();

                Username.Enabled = false;
                Password.Enabled = false;
            }
            else
            {
                Username.Clear();
                Password.Clear();

                Username.Enabled = true;
                Password.Enabled = true ;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
               
                if (UseWin.Checked)
                {
                    MainSQLCon.ConnectionString = "Data Source=" + Servername.Text + ";Integrated Security=SSPI;";
                }
                else
                {
                    MainSQLCon.ConnectionString = "Data Source=" + Servername.Text + ";User Id=" + Username.Text + ";Password=" + Password.Text + ";";
                }
                try
                {
                    MainSQLCon.Open();
                    if (MainSQLCon.State == ConnectionState.Open)
                    {
                        ConStat = true;
                        MainSQLCon.Close();
                        MessageBox.Show("Connection OK!");
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
